﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FWMS.DAO
{
    class UserDao
    {
        public Bean.UserBean userDaoSelect(Bean.UserBean bean)
        {
            DB.DBbase dbbase = new DB.DBbase();
            string sql = ""; // as user 
            sql = "select * from userguanli where name='" + bean.Username + "' and password='" + bean.Password+"'";
            if (dbbase.ExecuteSQL(sql.Trim()))
            {
                if (dbbase.rows.Length!=0)
                {
                    bean.Username = (string)dbbase.rows[0, 1];
                    bean.Password = (string)dbbase.rows[0, 2];
                }
                else
                {
                    bean.Username = null;
                    bean.Password = null;
                }
            }
            else
            {
                bean.Username = null;
                bean.Password = null;
            }
            return bean;
        }

        public bool userDaoUpdate(Bean.UserBean bean)
        {
            DB.DBbase dbbase = new DB.DBbase();
            string sql = ""; // as user 
            sql = "update userguanli set [password] = '"+bean.Password+"' where name='" + bean.Username + "'";
            if (!dbbase.ExecuteSQL(sql.Trim()))
            {
                return false;
            }
            else
            {
                return true;
            }
            }
    
        
    }
}
